package com.huangsm.book.designmodel.key;

import java.util.ArrayList;
import java.util.List;

/**
 * 使用同步关键字
 * @author huang
 * @date 2019/2/20
 */
public class SychronizedTest {
    private List list=new ArrayList();
    public synchronized Object pop()throws InterruptedException{
        while (list.size()==0){
            this.wait();
        }
        if (list.size()>0){
            return list.remove(0);
        }else {
            return null;
        }
    }
    public synchronized void put(Object o){
        list.add(o);
        this.notify();
    }
}
